package com.ler.yrmall.order.rpc;

import cn.hutool.core.bean.BeanUtil;
import com.ler.yrmall.basic.Result;
import com.ler.yrmall.order.api.OrderApi;
import com.ler.yrmall.order.dto.OrderDTO;
import com.ler.yrmall.order.entity.OrderEntity;
import com.ler.yrmall.order.service.OrderService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author Leron
 * @version 1.0
 */
@DubboService
public class OrderApiImpl implements OrderApi {

    @Resource
    private OrderService orderService;

    @Override
    public Result<OrderDTO> getOrderByOrderSn(String orderSn) {
        OrderEntity order = orderService.getOrderByOrderSn(orderSn);
        OrderDTO orderDTO = BeanUtil.copyProperties(order, OrderDTO.class);
        return Result.ok(orderDTO);
    }

    @Override
    public Long getOrderCount() {
        return orderService.count();
    }

    @Override
    public BigDecimal getTradeAmount() {
        return orderService.getTradeAmount();
    }
}
